home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** Program: MacShell
- ** File: help.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1991 Apple Computer, Inc.
- ** All rights reserved.
- */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "MacShell.h" /* Get the MacShell includes/typedefs, etc. */
- #include "MacShellCommon.h" /* Get the stuff in common with rez. */
- #include "MacShell.protos" /* Get the prototypes for MacShell. */
-
- #ifndef __BALLOONS__
- #include <Balloons.h>
- #endif
-
- #ifndef __PROCESSES__
- #include <Processes.h>
- #endif
-
- #ifdef THINK_C
- #include "Utilities.h"
- #else
- #ifndef __UTILITIES__
- #include <Utilities.h>
- #endif
- #endif
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- #pragma segment Main
- void DynamicBalloonHelp(void)
- {
- WindowPtr window, oldPort;
- ProcessSerialNumber cpsn, fpsn;
- FileRecHndl frHndl;
- Point mouseLoc, tip;
- ControlHandle ctl;
- Rect rct;
- short part, message, pos;
- HMMessageRecord helpMessage;
- Boolean procsSame;
- static short lastMessage;
- static short position[4] = {5, 6, 2, 1};
- #if MACSHELL_VERSION
- TEHandle teHndl;
- #endif
-
- if (gSystemVersion < 0x0700) return;
- /* The system can't support balloons. */
-
- if ((!HMGetBalloons()) || (!IsAppWindow(FrontWindow()))) {
- lastMessage = 0;
- return;
- } /* Balloons have been turned off, or it isn't our window anymore. */
-
- HMGetBalloonWindow(&window);
- if (!window) lastMessage = 0;
- /* There is no balloon currently, so there is no last message. */
-
- tip = mouseLoc = GetGlobalMouse();
- part = FindWindow(mouseLoc, &window);
- if ((window != FrontWindow()) || (part != inContent)) {
- lastMessage = 0;
- return;
- } /* We aren't over the content of the front window, so leave. */
-
- GetCurrentProcess(&cpsn);
- GetFrontProcess(&fpsn);
- SameProcess(&cpsn, &fpsn, &procsSame);
- if (!procsSame) {
- lastMessage = 0;
- return;
- } /* We aren't the front process, so leave. */
-
- GetPort(&oldPort);
- frHndl = (FileRecHndl)GetWRefCon(window);
- SetPort(window);
- GlobalToLocal(&mouseLoc);
-
- ctl = ((WindowPeek)window)->controlList;
- while (ctl) {
- rct = (*ctl)->contrlRect;
- if (PtInRect(mouseLoc, &rct)) break;
- ctl = (*ctl)->nextControl;
- } /* Find the control that we are over. */
-
- message = 0;
- if (ctl) {
-
- #if MACSHELL_VERSION
-
- teHndl = (TEHandle)GetCRefCon(ctl);
- if (teHndl == (*frHndl)->doc.inBox) message = 2;
- if (teHndl == (*frHndl)->doc.outBox) message = 4;
-
- #endif
-
- }
-
- if (message) {
-
- #if MACSHELL_VERSION
-
- if ((*frHndl)->connect.connected) --message;
-
- #endif
-
- if (lastMessage != message) { /* If this balloon isn't current balloon... */
- lastMessage = message;
- helpMessage.hmmHelpType = khmmStringRes;
- helpMessage.u.hmmStringRes.hmmResID = rDynHelpStrings;
- helpMessage.u.hmmStringRes.hmmIndex = message;
- LocalToGlobalRect(&rct);
- pos = (tip.v > (rct.top + rct.bottom) / 2) ? 2 : 0;
- if (tip.h > (rct.left + rct.right) / 2) ++pos;
- pos = position[pos];
- SetOrigin(0, 0);
- HMShowBalloon(&helpMessage, tip, &rct, nil, 0, pos, kHMRegularWindow);
- }
- }
- else {
- if (lastMessage) HMRemoveBalloon();
- lastMessage = 0;
- }
-
- SetOrigin(0, 0);
- SetPort(oldPort);
- }
-
-
-
-